import json
import time

import requests

from confluence_api import ConfluenceApi

c = ConfluenceApi(
    'https://ar.intra.nsfocus.com',
    'ar1',
    'tpo@31580')
link_list = [

    'https://app.clientservices.gartner.com/e/er?s=154878491&elqTarget=aHR0cHM6Ly93d3cuZ2FydG5lci5jb20vZG9jdW1lbnQvNDAyMjIyOT9yZWY9VHJhY2tEQkRhaWx5RW1haWw1&elq=02d5bf45d6a8465284461a65a1fa0e2c&elqaid=43307&elqat=1&elqTrackId=ba55a7ab958946cb82e4b97cea2ed045',
    # 'https://app.clientservices.gartner.com/e/er?s=154878491&elqTarget=aHR0cHM6Ly93d3cuZ2FydG5lci5jb20vZG9jdW1lbnQvNDAyMjE5Mj9yZWY9VHJhY2tEQkRhaWx5RW1haWw1&elq=02d5bf45d6a8465284461a65a1fa0e2c&elqaid=43307&elqat=1&elqTrackId=37ce776f403a4874a34ceee4eb15e696',
    # 'https://app.clientservices.gartner.com/e/er?s=154878491&elqTarget=aHR0cHM6Ly93d3cuZ2FydG5lci5jb20vZG9jdW1lbnQvNDAyMjE4Mj9yZWY9VHJhY2tEQkRhaWx5RW1haWw1&elq=02d5bf45d6a8465284461a65a1fa0e2c&elqaid=43307&elqat=1&elqTrackId=5f4d3fa7ee4944bf8fde31dc49221c1a',
    'https://app.clientservices.gartner.com/e/er?s=154878491&elqTarget=aHR0cHM6Ly93d3cuZ2FydG5lci5jb20vZG9jdW1lbnQvNDAyMjI0OT9yZWY9VHJhY2tEQkRhaWx5RW1haWw1&elq=02d5bf45d6a8465284461a65a1fa0e2c&elqaid=43307&elqat=1&elqTrackId=8525a934051248b6883b3a8e05550e39',
    # 'https://app.clientservices.gartner.com/e/er?s=154878491&elqTarget=aHR0cHM6Ly93d3cuZ2FydG5lci5jb20vZG9jdW1lbnQvNDAyMjIyND9yZWY9VHJhY2tEQkRhaWx5RW1haWw1&elq=02d5bf45d6a8465284461a65a1fa0e2c&elqaid=43307&elqat=1&elqTrackId=cb1e2e3654844d998e16e7079d541952',
    'https://app.clientservices.gartner.com/e/er?s=154878491&elqTarget=aHR0cHM6Ly93d3cuZ2FydG5lci5jb20vZG9jdW1lbnQvNDAyMjE4OD9yZWY9VHJhY2tEQkRhaWx5RW1haWw1&elq=02d5bf45d6a8465284461a65a1fa0e2c&elqaid=43307&elqat=1&elqTrackId=708a61fd9efd4281aeeb99f3f0e2cb5d',
    # 'https://app.clientservices.gartner.com/e/er?s=154878491&elqTarget=aHR0cHM6Ly93d3cuZ2FydG5lci5jb20vZG9jdW1lbnQvNDAyMjIxOD9yZWY9VHJhY2tEQkRhaWx5RW1haWw1&elq=02d5bf45d6a8465284461a65a1fa0e2c&elqaid=43307&elqat=1&elqTrackId=abc967dddf214115bf566c3bfdc98f12',
    # 'https://app.clientservices.gartner.com/e/er?s=154878491&elqTarget=aHR0cHM6Ly93d3cuZ2FydG5lci5jb20vZG9jdW1lbnQvNDAyMjI0NT9yZWY9VHJhY2tEQkRhaWx5RW1haWw1&elq=02d5bf45d6a8465284461a65a1fa0e2c&elqaid=43307&elqat=1&elqTrackId=e4236f7437214f78beff849eb0c11163',
    # 'https://app.clientservices.gartner.com/e/er?s=154878491&elqTarget=aHR0cHM6Ly93d3cuZ2FydG5lci5jb20vZG9jdW1lbnQvNDAyMjE3MD9yZWY9VHJhY2tEQkRhaWx5RW1haWw1&elq=02d5bf45d6a8465284461a65a1fa0e2c&elqaid=43307&elqat=1&elqTrackId=1f8137afbd23402b8b96d4b968604e23',
    # 'https://app.clientservices.gartner.com/e/er?s=154878491&elqTarget=aHR0cHM6Ly93d3cuZ2FydG5lci5jb20vZG9jdW1lbnQvNDAyMjE3Nj9yZWY9VHJhY2tEQkRhaWx5RW1haWw1&elq=02d5bf45d6a8465284461a65a1fa0e2c&elqaid=43307&elqat=1&elqTrackId=55ebb17c4f354e33b5221179f5dffe70',
    # 'https://app.clientservices.gartner.com/e/er?s=154878491&elqTarget=aHR0cHM6Ly93d3cuZ2FydG5lci5jb20vZG9jdW1lbnQvNDAyMjIwNz9yZWY9VHJhY2tEQkRhaWx5RW1haWw1&elq=02d5bf45d6a8465284461a65a1fa0e2c&elqaid=43307&elqat=1&elqTrackId=3c199ecda95c45c0be762f2fec3c6752',
    # 'https://app.clientservices.gartner.com/e/er?s=154878491&elqTarget=aHR0cHM6Ly93d3cuZ2FydG5lci5jb20vZG9jdW1lbnQvNDAyMjIzNj9yZWY9VHJhY2tEQkRhaWx5RW1haWw1&elq=02d5bf45d6a8465284461a65a1fa0e2c&elqaid=43307&elqat=1&elqTrackId=7be367ce072747c0a2c58f566be7dadf',
    # 'https://app.clientservices.gartner.com/e/er?s=154878491&elqTarget=aHR0cHM6Ly93d3cuZ2FydG5lci5jb20vZG9jdW1lbnQvNDAyMjE3Nz9yZWY9VHJhY2tEQkRhaWx5RW1haWw1&elq=02d5bf45d6a8465284461a65a1fa0e2c&elqaid=43307&elqat=1&elqTrackId=59c53870367b43c2904005ccf203009c',
    'https://app.clientservices.gartner.com/e/er?s=154878491&elqTarget=aHR0cHM6Ly93d3cuZ2FydG5lci5jb20vZG9jdW1lbnQvNDAyMjI1NT9yZWY9VHJhY2tEQkRhaWx5RW1haWw1&elq=02d5bf45d6a8465284461a65a1fa0e2c&elqaid=43307&elqat=1&elqTrackId=daa7b2acd9fb4d18b0866c3c69f1d5ac',
    # 'https://app.clientservices.gartner.com/e/er?s=154878491&elqTarget=aHR0cHM6Ly93d3cuZ2FydG5lci5jb20vZG9jdW1lbnQvNDAyMjE3OT9yZWY9VHJhY2tEQkRhaWx5RW1haWw1&elq=02d5bf45d6a8465284461a65a1fa0e2c&elqaid=43307&elqat=1&elqTrackId=2d47cf8d72684502b03468b6720babf1',
    # 'https://app.clientservices.gartner.com/e/er?s=154878491&elqTarget=aHR0cHM6Ly93d3cuZ2FydG5lci5jb20vZG9jdW1lbnQvNDAyMjE2NT9yZWY9VHJhY2tEQkRhaWx5RW1haWw1&elq=02d5bf45d6a8465284461a65a1fa0e2c&elqaid=43307&elqat=1&elqTrackId=eef2d690f2ea4af6bc32a4772054971b',
    # 'https://app.clientservices.gartner.com/e/er?s=154878491&elqTarget=aHR0cHM6Ly93d3cuZ2FydG5lci5jb20vZG9jdW1lbnQvNDAyMjE4Mz9yZWY9VHJhY2tEQkRhaWx5RW1haWw1&elq=02d5bf45d6a8465284461a65a1fa0e2c&elqaid=43307&elqat=1&elqTrackId=787d05cabbce49efbc71dda3cbf56170',
    # 'https://app.clientservices.gartner.com/e/er?s=154878491&elqTarget=aHR0cHM6Ly93d3cuZ2FydG5lci5jb20vZG9jdW1lbnQvNDAyMjIzMD9yZWY9VHJhY2tEQkRhaWx5RW1haWw1&elq=02d5bf45d6a8465284461a65a1fa0e2c&elqaid=43307&elqat=1&elqTrackId=d1763ac33eb44918bc1152740d9ae60c',
    # 'https://app.clientservices.gartner.com/e/er?s=154878491&elqTarget=aHR0cHM6Ly93d3cuZ2FydG5lci5jb20vZG9jdW1lbnQvNDAyMjIxOT9yZWY9VHJhY2tEQkRhaWx5RW1haWw1&elq=02d5bf45d6a8465284461a65a1fa0e2c&elqaid=43307&elqat=1&elqTrackId=f241647366f348b48064533ebe6f5d79',
    # 'https://app.clientservices.gartner.com/e/er?s=154878491&elqTarget=aHR0cHM6Ly93d3cuZ2FydG5lci5jb20vZG9jdW1lbnQvNDAyMjI0Mj9yZWY9VHJhY2tEQkRhaWx5RW1haWw1&elq=02d5bf45d6a8465284461a65a1fa0e2c&elqaid=43307&elqat=1&elqTrackId=e20cb25654d94f2e9e942801f01bd244',
    # 'https://app.clientservices.gartner.com/e/er?s=154878491&elqTarget=aHR0cHM6Ly93d3cuZ2FydG5lci5jb20vZG9jdW1lbnQvNDAyMjIyMD9yZWY9VHJhY2tEQkRhaWx5RW1haWw1&elq=02d5bf45d6a8465284461a65a1fa0e2c&elqaid=43307&elqat=1&elqTrackId=97f820d3d88e4100a5e325c7b3c134ea',
    # 'https://app.clientservices.gartner.com/e/er?s=154878491&elqTarget=aHR0cHM6Ly93d3cuZ2FydG5lci5jb20vZG9jdW1lbnQvNDAyMjI0Nz9yZWY9VHJhY2tEQkRhaWx5RW1haWw1&elq=02d5bf45d6a8465284461a65a1fa0e2c&elqaid=43307&elqat=1&elqTrackId=c235fb30538b4a01b51ac752aa38ca76',
]
for link in link_list:
    # link = input("请输入爬取链接：")

    headers = {
        'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/107.0.0.0 Safari/537.36',
        'Connection': 'close'
    }
    data = json.dumps({'link': link})
    s = requests.session()
    s.keep_alive = False
    req = requests.post('http://192.168.19.16:9111/arGartnerPdfSpider', data=data, headers=headers)
    # print(req)
    # print(req.json())
    time.sleep(5)
    print('5--爬虫方响应内容：', req, '-----------', req.json())
    # ar_url = req.json()['data']
    # print(ar_url)
    if req.json()['code'] == 200:
        time.sleep(300)
        # 提取ar阅览室链接
        req2 = requests.post('http://192.168.19.16:9111/isGartnerLinkInAR', data=data, headers=headers)
        if req2.json()['code'] == 201:
            print(req2.json())
            ar_url = req2.json()['data']
            print(ar_url)
            time.sleep(300)
        elif req2.json()['code'] == 200:
            print(req2.json(), '----------------爬取失败')
    # if req.status_code == '200':
    #     have_q = c.search(title=title, spaceKey='AR')['results']
    #     if not have_q:
    #         # print(title, '----', link, '----文章上传失败')
    #     else:
    #         print('文章上传成功')
